home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / lib / rcscripts / sh / rc-help.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2006-04-25  |  7KB  |  239 lines

  1. #!/bin/bash
  2. # Copyright 1999-2005 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4.  
  5. source /sbin/functions.sh
  6.  
  7. if [[ ${RC_NOCOLOR} == "yes" ]] ; then
  8.     unset BLUE GREEN OFF CYAN
  9. else
  10.     BLUE="\033[34;01m"
  11.     GREEN="\033[32;01m"
  12.     OFF="\033[0m"
  13.     CYAN="\033[36;01m"
  14. fi
  15.  
  16. myscript=$1
  17. if [[ -z ${myscript} ]] ; then
  18.     echo "Please execute an init.d script"
  19.     exit 1
  20. fi
  21.  
  22. if [[ -L ${myscript} ]] ; then
  23.     myservice=$(readlink "${myscript}")
  24. else
  25.     myservice=${myscript}
  26. fi
  27. myservice=${myservice##*/}
  28.  
  29. if [[ $2 == "help" ]] ; then
  30.     BE_VERBOSE="yes"
  31.     NL=$'\n'
  32. else
  33.     BE_VERBOSE="no"
  34.     NL=""
  35. fi
  36.  
  37. default_opts="start stop restart pause zap"
  38. extra_opts=$(source "${myscript}" 2>/dev/null ; echo ${opts})
  39.  
  40. if [[ ${BE_VERBOSE} == "yes" ]] ; then
  41. echo -e "
  42. ${GREEN}Gentoo RC-Scripts; ${BLUE}http://www.gentoo.org/${OFF}
  43.  Copyright 1999-2005 Gentoo Foundation; Distributed under the GPL
  44. "
  45. fi
  46.  
  47. echo -e "Usage: ${CYAN}${myservice}${OFF} [ ${GREEN}flags${OFF} ] < ${GREEN}options${OFF} >
  48.  
  49. ${CYAN}Normal Options:${OFF}"
  50.  
  51. if [[ ${BE_VERBOSE} == "yes" ]] ; then
  52. echo -e "
  53.     ${GREEN}start${OFF}
  54.       Start service, as well as the services it depends on (if not already
  55.       started).
  56.  
  57.     ${GREEN}stop${OFF}
  58.       Stop service, as well as the services that depend on it (if not already
  59.       stopped).
  60.  
  61.     ${GREEN}restart${OFF}
  62.       Restart service, as well as the services that depend on it.
  63.  
  64.       Note to developers:  If this function is replaced with a custom one,
  65.       'svc_start' and 'svc_stop' should be used instead of 'start' and
  66.       'stop' to restart the service.  This is so that the dependencies
  67.       can be handled correctly.  Refer to the portmap rc-script for an
  68.       example.
  69.  
  70.     ${GREEN}pause${OFF}
  71.       Same as 'stop', but the services that depends on it, will not be
  72.       stopped.  This is useful for stopping a network interface without
  73.       stopping all the network services that depend on 'net'.
  74.  
  75.     ${GREEN}zap${OFF}
  76.       Reset a service that is currently stopped, but still marked as started,
  77.       to the stopped state.  Basically for killing zombie services.
  78.  
  79.     ${GREEN}status${OFF}
  80.       Prints \"status:  started\" if the service is running, else it
  81.       prints \"status:  stopped\".
  82.  
  83.       Note that if the '--quiet' flag is given, it will return true if the
  84.       service is running, else false.
  85.  
  86.     ${GREEN}ineed|iuse${OFF}
  87.       List the services this one depends on.  Consult the section about
  88.       dependencies for more info on the different types of dependencies.
  89.  
  90.     ${GREEN}needsme|usesme${OFF}
  91.       List the services that depend on this one.  Consult the section about
  92.       dependencies for more info on the different types of dependencies.
  93.  
  94.     ${GREEN}broken${OFF}
  95.       List the missing or broken dependencies of type 'need' this service
  96.       depends on.
  97. "
  98.  
  99. else
  100.  
  101. echo -e "    ${GREEN}${default_opts}${OFF}
  102.       Default init.d options."
  103.  
  104. fi
  105.  
  106. if [[ -n ${extra_opts} ]] ; then
  107. echo -e "
  108. ${CYAN}Additional Options:${OFF}${NL}
  109.     ${GREEN}${extra_opts}${OFF}
  110.       Extra options supported by this init.d script."
  111. fi
  112.  
  113. echo -e "
  114. ${CYAN}Flags:${OFF}${NL}
  115.     ${GREEN}--quiet${OFF}
  116.       Suppress output to stdout, except if:${NL}
  117.       1) It is a warning, then output to stdout
  118.       2) It is an error, then output to stderr${NL}
  119.     ${GREEN}--nocolor${OFF}
  120.       Suppress the use of colors."
  121.  
  122. if [[ ${BE_VERBOSE} == "yes" ]] ; then
  123. echo -e "
  124. ${CYAN}Dependencies:${OFF}
  125.  
  126.     This is the heart of the Gentoo RC-Scripts, as it determines the order
  127.     in which services gets started, and also to some extend what services
  128.     get started in the first place.
  129.  
  130.     The following example demonstrates how to use dependencies in
  131.     rc-scripts:
  132.  
  133.     depend() {
  134.         need foo bar
  135.         use ray
  136.     }
  137.  
  138.     Here we have foo and bar as dependencies of type 'need', and ray of
  139.     type 'use'.  You can have as many dependencies of each type as needed, as
  140.     long as there is only one entry for each type, listing all its dependencies
  141.     on one line only.
  142.  
  143.     ${GREEN}need${OFF}
  144.       These are all the services needed for this service to start.  If any
  145.       service in the 'need' line is not started, it will be started even if it
  146.       is not in the current, or 'boot' runlevel, and then this service will be
  147.       started.  If any services in the 'need' line fails to start or is
  148.       missing, this service will never be started.
  149.  
  150.     ${GREEN}use${OFF}
  151.       This can be seen as representing optional services this service depends on
  152.       that are not critical for it to start.  For any service in the 'use' line,
  153.       it must be added to the 'boot' or current runlevel to be considered a
  154.       valid 'use' dependency.  It can also be used to determine startup order.
  155.  
  156.     ${GREEN}before${OFF}
  157.       This, together with the 'after' dependency type, can be used to control
  158.       startup order.  In core, 'before' and 'after' do not denote a dependency,
  159.       but should be used for order changes that will only be honoured during
  160.       a change of runlevel.  All services listed will get started *after* the
  161.       current service.  In other words, this service will get started *before*
  162.       all listed services.
  163.  
  164.     ${GREEN}after${OFF}
  165.       All services listed will be started *before* the current service.  Have a
  166.       look at 'before' for more info.
  167.  
  168.     ${GREEN}provide${OFF}
  169.       This is not really a dependency type, rather it will enable you to create
  170.       virtual services.  This is useful if there is more than one version of
  171.       a specific service type, system loggers or crons for instance.  Just
  172.       have each system logger provide 'logger', and make all services in need
  173.       of a system logger depend on 'logger'.  This should make things much more
  174.       generic.
  175.  
  176.     Note that the 'need', 'use', 'before', and 'after' dependency types accept
  177.     an '*' as an argument.  Having:
  178.  
  179.     depend() {
  180.         before *
  181.     }
  182.  
  183.     will make the service start first in the current runlevel, and:
  184.  
  185.     depend() {
  186.         after *
  187.     }
  188.  
  189.     will make the service the last to start.
  190.  
  191.     You should however be careful how you use this, as I really will not
  192.     recommend using it with the 'need' or 'use' dependency type ... you have
  193.     been warned!
  194.  
  195. ${CYAN}'net' Dependency and 'net.*' Services:${OFF}
  196.  
  197.     Example:
  198.  
  199.     depend() {
  200.         need net
  201.     }
  202.  
  203.     This is a special dependency of type 'need'.  It represents a state where
  204.     a network interface or interfaces besides lo is up and active.  Any service
  205.     starting with 'net.' will be treated as a part of the 'net' dependency,
  206.     if:
  207.  
  208.     1.  It is part of the 'boot' runlevel
  209.     2.  It is part of the current runlevel
  210.  
  211.     A few examples are the /etc/init.d/net.eth0 and /etc/init.d/net.lo services."
  212. fi
  213.  
  214. echo -e "
  215. ${CYAN}Configuration files:${OFF}"
  216.  
  217. if [[ ${BE_VERBOSE} == "yes" ]] ; then
  218. echo -e "
  219.     There are two files which will be sourced for possible configuration by
  220.     the rc-scripts.  They are (sourced from top to bottom):
  221. "
  222. fi
  223.  
  224. echo -e "    /etc/conf.d/${myservice}${NL}    /etc/rc.conf"
  225.  
  226. if [[ ${BE_VERBOSE} == "yes" ]] ; then
  227. echo -e "
  228. ${CYAN}Management:${OFF}
  229.  
  230.     Services are added and removed via the 'rc-update' tool.  Running it without
  231.     arguments should give sufficient help.
  232. "
  233. else
  234. echo -e "
  235. For more info, please run '${myscript} help'."
  236. fi
  237.  
  238. exit 0
  239.